//剑指offer题3：输入一个链表，从尾到头打印链表每个结点的值
//      思路一：递归       思路二：顺序遍历链表存入vector数组，
#include<iostream>
#include<stdio.h>
using namespace std;
struct FlistNode
{
	int val;
	FlistNode *next;
	FlistNode(const int x) :val(x), next(0){}
};
void PrintListFromTailtoHead(FlistNode *root)//递归
{
	if (!root)return;
	PrintListFromTailtoHead(root->next);
	printf("%d ", root->val);
}
int main()
{
	FlistNode *head1 = new FlistNode(1);
	FlistNode *head2 = new FlistNode(2); head1->next = head2;
	FlistNode *head3 = new FlistNode(3); head2->next = head3;
	FlistNode *head4 = new FlistNode(4); head3->next = head4;
	FlistNode *head5 = new FlistNode(5); head4->next = head5;
	PrintListFromTailtoHead(head1);
	cout << endl;

	return 0;
}
